<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>面试评分权重设置</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/bootstrap/5.1.3/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/boxicons@2.0.7/css/boxicons.min.css" rel="stylesheet">
    <style>
        :root {
            --primary-color: #4a90e2;
            --error-color: #ff4d4f;
            --success-color: #52c41a;
            --border-radius: 8px;
            --gradient-purple: linear-gradient(135deg, #9c27b0, #673ab7);
        }

        body {
            background-color: #f5f7fa;
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
            min-height: 100vh;
            display: flex;
            align-items: center;
            margin: 0;
            padding: 20px 0;
        }

        .weight-container {
            max-width: 700px;
            margin: 0 auto;
            padding: 20px;
            background: white;
            border-radius: var(--border-radius);
            box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
        }

        .page-title {
            color: white;
            font-size: 20px;
            font-weight: 600;
            margin-bottom: 15px;
            padding: 12px 20px;
            background: var(--gradient-purple);
            border-radius: var(--border-radius);
            box-shadow: 0 2px 8px rgba(156, 39, 176, 0.2);
        }

        .form-label {
            font-weight: 500;
            color: #4a5568;
            margin-bottom: 4px;
            font-size: 14px;
        }

        .form-control {
            border: 2px solid #e2e8f0;
            border-radius: var(--border-radius);
            padding: 6px 12px;
            height: auto;
            transition: all 0.3s ease;
        }

        .form-control:focus {
            border-color: var(--primary-color);
            box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
        }

        .weight-group {
            position: relative;
            margin-bottom: 12px;
            padding: 12px;
            background: #f8fafc;
            border-radius: var(--border-radius);
            transition: all 0.3s ease;
        }

        .weight-group:hover {
            background: #f1f5f9;
        }

        .weight-icon {
            position: absolute;
            right: 15px;
            top: 50%;
            transform: translateY(-50%);
            color: var(--primary-color);
            font-size: 18px;
            opacity: 0.5;
        }

        .weight-sum {
            margin: 15px 0;
            padding: 12px 20px;
            background: var(--gradient-purple);
            border-radius: var(--border-radius);
            color: white;
            font-weight: 600;
            display: flex;
            align-items: center;
            justify-content: space-between;
            font-size: 14px;
            box-shadow: 0 2px 8px rgba(156, 39, 176, 0.2);
        }

        .weight-sum.invalid {
            background: linear-gradient(135deg, #f44336, #e91e63);
            color: white;
        }

        .btn-primary {
            background-color: var(--primary-color);
            border: none;
            padding: 10px 20px;
            border-radius: var(--border-radius);
            font-weight: 600;
            transition: all 0.3s ease;
            margin-top: 10px;
        }

        .btn-primary:hover {
            background-color: #357abd;
            transform: translateY(-1px);
            box-shadow: 0 4px 12px rgba(74, 144, 226, 0.2);
        }

        @media (max-width: 768px) {
            body {
                padding: 10px;
            }
            .weight-container {
                margin: 0 10px;
                padding: 15px;
            }
            .weight-group {
                padding: 10px;
                margin-bottom: 10px;
            }
        }
    </style>
</head>
<body>
    <div class="container weight-container">
        <h2 class="page-title">面试评分权重设置</h2>
        <form id="weightForm">
            <div class="weight-group">
                <label for="technical_weight" class="form-label">技术能力权重</label>
                <input type="number" class="form-control weight-input" id="technical_weight" 
                       step="0.01" min="0" max="1" required>
                <i class='bx bx-code-alt weight-icon'></i>
            </div>
            <div class="weight-group">
                <label for="learning_weight" class="form-label">学习能力权重</label>
                <input type="number" class="form-control weight-input" id="learning_weight" 
                       step="0.01" min="0" max="1" required>
                <i class='bx bx-book weight-icon'></i>
            </div>
            <div class="weight-group">
                <label for="team_weight" class="form-label">团队协作权重</label>
                <input type="number" class="form-control weight-input" id="team_weight" 
                       step="0.01" min="0" max="1" required>
                <i class='bx bx-group weight-icon'></i>
            </div>
            <div class="weight-group">
                <label for="problem_solving_weight" class="form-label">问题解决权重</label>
                <input type="number" class="form-control weight-input" id="problem_solving_weight" 
                       step="0.01" min="0" max="1" required>
                <i class='bx bx-bulb weight-icon'></i>
            </div>
            <div class="weight-group">
                <label for="communication_weight" class="form-label">沟通表达权重</label>
                <input type="number" class="form-control weight-input" id="communication_weight" 
                       step="0.01" min="0" max="1" required>
                <i class='bx bx-conversation weight-icon'></i>
            </div>
            <div class="weight-sum">
                <span>权重总和</span>
                <span id="weightSum">0</span>
            </div>
            <button type="submit" class="btn btn-primary w-100" id="submitBtn">保存设置</button>
        </form>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // 获取当前权重设置
            fetch('/api/score-weights')
                .then(response => response.json())
                .then(data => {
                    Object.keys(data).forEach(key => {
                        document.getElementById(key).value = data[key];
                    });
                    updateWeightSum();
                });

            // 监听输入变化，更新总和
            document.querySelectorAll('.weight-input').forEach(input => {
                input.addEventListener('input', updateWeightSum);
            });

            // 提交表单
            document.getElementById('weightForm').addEventListener('submit', function(e) {
                e.preventDefault();
                
                const weightSum = calculateWeightSum();
                if (Math.abs(weightSum - 1) > 0.001) {
                    alert('所有权重之和必须等于1');
                    return;
                }

                const data = {};
                document.querySelectorAll('.weight-input').forEach(input => {
                    data[input.id] = parseFloat(input.value);
                });

                fetch('/api/score-weights', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify(data)
                })
                .then(response => response.json())
                .then(data => {
                    if (data.error) {
                        alert(data.error);
                    } else {
                        alert('权重更新成功！');
                    }
                });
            });

            function updateWeightSum() {
                const sum = calculateWeightSum();
                const sumElement = document.getElementById('weightSum');
                sumElement.textContent = sum.toFixed(2);
                
                const weightSumDiv = document.querySelector('.weight-sum');
                if (Math.abs(sum - 1) > 0.001) {
                    weightSumDiv.classList.add('invalid');
                } else {
                    weightSumDiv.classList.remove('invalid');
                }
            }

            function calculateWeightSum() {
                let sum = 0;
                document.querySelectorAll('.weight-input').forEach(input => {
                    sum += parseFloat(input.value) || 0;
                });
                return sum;
            }
        });
    </script>
</body>
</html> 